import { defineStore } from "pinia";
import { registerApi, getAddUserInfo, deleteuserInfoApi, setUserStoreInfoApi, getAllShopDataApi } from "@/api/modules/user.js"


export const userManage = defineStore("userManage", {
    state: () => {
        return {
            userinfo: [],//用户列表数据
            userData: {},//用户的数据
            userShopData: {
                id: 0,
                shopName: "",
                shopAddress: "",
                status: "0",
                distance: "",
                phone: "",
                latitude: 0,
                longitude: 0,
                openTime: "",
                storeImg: "",
                shopId: 0
            },//店铺数据
            shopListData: [],//商店地址列表
            imgUrl:"",//图片地址

        }
    },

    actions: {

        //注册用户
        async registerUser(userinfo) {
            // console.log(userinfo,"用户传来的数据再stores里面show")
            let res = await registerApi(userinfo)

            // console.log(res,"数据")
            return res;
        },

        //获取用户的数据
        async getUserData() {
            let res = await getAddUserInfo()

            // console.log(res,"这是用户的数据")

            if (res.code) {
                this.userinfo = res.data
            } else {
                this.userinfo = []
            }

        },


        //更新userData的表数据
        updatauserData(data) {
            this.userData = data
            // console.log(data,"updatauserData粉色粉色是·啊啊啊啊啊啊啊啊啊")
        },

        //删除商家的数据
        async deleteUserInfo(data) {
            let res = await deleteuserInfoApi(data);
            // console.log(res, "删除后的信息返回");
            return res;
        },

        //更新部分userData的表数据
        updatauserShopData(data) {
            this.userShopData.id = data.id
            this.userShopData.phone = data.iphone

            this.userShopData.shopName=''
            this.userShopData.shopAddress=''
            this.userShopData.status=''
            this.userShopData.latitude=0
            this.userShopData.longitude=0
            this.userShopData.openTime=''   
            this.userShopData.storeImg=''
            this.userShopData.shopId=0
           


        
             
              
            
                
             
            // console.log(data, "updatauserData粉色粉色是·")
        },

        //更新所有userData的表数据
        upAlluserShopData(data) {
            this.userShopData= data
           
            // console.log(data, "updatauserData粉色粉色是·")
        },


        //设置用户店铺位置信息
        async setUserStoreInfo(data) {
            let res = await setUserStoreInfoApi(data)


            return res

            // console.log(res, "设置用户店铺位置信息，设置成功的信息")
        },

        //获取所有店铺信息
        async getAllShopData() {
            let res = await getAllShopDataApi()
            // console.log(res, "返回来的数据")
            this.shopListData = res.data

            return res

        }

    }



})